package service;

import org.joda.time.DateTime;

import java.sql.Timestamp;

/**
 * 项目用海特殊字段对应表
 */
public class FieldMappingServiceElasticSearchImpl implements FieldMappingService{
    @Override
    public Object getValueByField(String columnName, Object object) {
        if (object==null){
            return object;
        }
        java.util.Date d2 = null;
        switch (columnName) {
            case "dateOfIssue":
                final java.sql.Timestamp timestamp = (Timestamp) object;
                d2 = new java.util.Date(timestamp.getTime());
                return new DateTime(d2).toString("yyyyMMdd'T'HHmmss.SSS'Z'");
            default:
                if (object instanceof java.sql.Date){
                    java.sql.Date d1 = (java.sql.Date) object;
                    d2 = new java.util.Date(d1.getTime());
                    return new DateTime(d2).toString("yyyyMMdd'T'HHmmss.SSS'Z'");
                }
               return object;
        }
    }
}
